home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Just Call Me Internet
/
Just Call Me Internet.iso
/
prog
/
atari
/
c
/
zmdm
/
fileio.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-06-26
|
2KB
|
128 lines
/*
* File I/O (with large buffers) Module
*
* Jwahar Bammi
* usenet: cwruecmp!bammi@decvax.UUCP
* csnet: bammi@cwru.edu
* arpa: bammi@cwru.edu
* CompuServe: 71515,155
*/
#include "zmdm.h"
#include "common.h"
#define O_RDONLY 1
#define O_WRONLY 2
#define O_APONLY 4
#define MBUFSIZ (((long)BBUFSIZ)-1L)
static unsigned char *bptr;
static long flcount = (-1L);
static char bufmode;
int stfopen(name, mode)
char *name, *mode;
{
register int handle;
switch(*mode)
{
case 'r':
if((handle = Fopen(name, 0)) <= 0)
return -1;
bufmode = O_RDONLY;
break;
case 'w':
if((handle = Fcreate(name, 0)) <= 0)
{
if((handle = Fopen(name, 1)) <= 0)
return -1;
}
bufmode = O_WRONLY;
break;
case 'a':
if((handle = Fopen(name, 2)) <= 0)
return -1;
Fseek(0L, handle, 2);
bufmode = O_APONLY;
break;
default:
return -1;
}
bptr = bufr;
flcount = (-1L);
return handle;
}
stfclose(handle)
int handle;
{
if(bufmode == O_RDONLY)
return Fclose(handle);
if(stflush(handle))
{
Fclose(handle);
return -1;
}
return Fclose(handle);
}
stputc(c, handle)
unsigned int c;
int handle;
{
if(flcount >= MBUFSIZ)
{
if(Fwrite(handle, (long)BBUFSIZ, bufr) != (long)BBUFSIZ)
return -1;
flcount = (-1L);
bptr = bufr;
}
flcount++;
return (*bptr++ = c);
}
stgetc(handle)
int handle;
{
if(flcount <= 0)
{
if((flcount = Fread(handle, (long)BBUFSIZ, bufr)) == 0)
return EOF;
bptr = bufr;
}
flcount--;
return(*bptr++);
}
stflush(handle)
int handle;
{
if(flcount < 0)
return 0;
if(Fwrite(handle, (long)(flcount+1L), bufr) != (flcount+1L))
return -1;
flcount = (-1L);
bptr = bufr;
return 0;
}
stfseek(handle, disp, mode)
int handle;
long disp;
int mode;
{
if(bufmode != O_RDONLY)
if(stflush(handle))
return -1;
Fseek(disp, handle, mode);
flcount = (-1L);
bptr = bufr;
return 0;
}